package cn.com.blueInfo.bpm.person.controller;

import cn.com.blueInfo.bpm.common.controller.BaseController;
import cn.com.blueInfo.bpm.common.validation.Create;
import cn.com.blueInfo.bpm.common.validation.Update;
import cn.com.blueInfo.bpm.common.validation.UpdatePartial;
import cn.com.blueInfo.bpm.person.request.UserAccountDTO;
import cn.com.blueInfo.bpm.person.response.UserAccountVO;
import cn.com.blueInfo.bpm.person.service.UserAccountService;
import cn.com.blueInfo.utils.result.ResultInfo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.groups.Default;
import java.util.List;

/**
 * 员工账户表 前端控制器
 * @author suxch
 * @since 2025-08-24 01:39:52
 */
@Tag(name = "员工账户 接口")
@RestController
@RequestMapping("/person/userAccount")
public class UserAccountController extends BaseController {

    @Autowired
    private UserAccountService userAccountService;

    /**
     * 新建员工账户
     * @param userAccountDTO 员工账户参数
     * @return ResultInfo
     */
    @Operation(summary = "新增员工账户")
    @PostMapping("/addInfo")
    public ResultInfo<Integer> createUserAccount(
            @Validated({Create.class, Default.class}) @RequestBody UserAccountDTO userAccountDTO) {
        return userAccountService.addUserAccount(userAccountDTO);
    }

    /**
     * 批量新建员工账户
     * @param userAccountDTOList 员工账户参数列表
     * @return ResultInfo
     */
    @Operation(summary = "批量新建员工账户")
    @PostMapping("/addInfoList")
    public ResultInfo<Integer> batchCreateUserAccount(
            @Validated({Create.class, Default.class}) @RequestBody List<UserAccountDTO> userAccountDTOList) {
        return userAccountService.batchAddUserAccount(userAccountDTOList);
    }

    /**
     * 根据ID删除员工账户
     * @param userAccountId 员工账户ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID删除员工账户")
    @DeleteMapping("/removeInfo/{userAccountId}")
    public ResultInfo<Integer> deleteUserAccountById(
            @Parameter(name = "ID") @PathVariable Long userAccountId) {
        return userAccountService.removeUserAccount(userAccountId);
    }

    /**
     * 批量根据ID删除员工账户
     * @param userAccountIdList 员工账户ID列表
     * @return ResultInfo
     */
    @Operation(summary = "批量根据ID删除员工账户")
    @DeleteMapping("/removeInfoList/{userAccountIdList}")
    public ResultInfo<Integer> batchDeleteUserAccountById(
            @Parameter(name = "ID") @PathVariable List<Long> userAccountIdList) {
        return userAccountService.batchRemoveUserAccount(userAccountIdList);
    }

    /**
     * 根据ID全量更新员工账户
     * @param userAccountId 员工账户ID
     * @param userAccountDTO 员工账户参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID全量更新员工账户")
    @PutMapping("/modifyInfo/{userAccountId}")
    public ResultInfo<Integer> updateUserAccountFull(
            @Parameter(name = "ID") @PathVariable Long userAccountId,
            @Validated({Update.class, Default.class}) @RequestBody UserAccountDTO userAccountDTO) {
        validateUpdateId(userAccountId, userAccountDTO.getId());
        return userAccountService.modifyUserAccount(userAccountDTO);
    }

    /**
     * 根据ID部分更新员工账户
     * @param userAccountId 员工账户ID
     * @param userAccountUpdatePartialDTO 员工账户参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID部分更新员工账户")
    @PatchMapping("/modifyPartialInfo/{userAccountId}")
    public ResultInfo<Integer> updateUserAccountPartial(
            @Parameter(name = "ID") @PathVariable Long userAccountId,
            @Validated({UpdatePartial.class, Default.class}) @RequestBody
            UserAccountDTO.UpdatePartialDTO userAccountUpdatePartialDTO) {
        validateUpdateId(userAccountId, userAccountUpdatePartialDTO.getId());
        return userAccountService.modifyUserAccountPartial(userAccountUpdatePartialDTO);
    }

    /**
     * 根据ID查询员工账户
     * @param userAccountId 员工账户ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID查询员工账户")
    @GetMapping("/getInfo/{userAccountId}")
    public ResultInfo<UserAccountVO> getUserAccountById(
            @Parameter(name = "ID") @PathVariable Long userAccountId) {
        return userAccountService.queryUserAccountById(userAccountId);
    }

    /**
     * 分页查询员工账户
     * @param userAccountQueryDTO 员工账户参数
     * @return ResultInfo
     */
    @Operation(summary = "分页查询员工账户")
    @GetMapping("/getInfos")
    public ResultInfo<Page<UserAccountVO>> getUserAccountPage(
            @Validated UserAccountDTO.QueryDTO userAccountQueryDTO) {
        return userAccountService.queryUserAccountPage(userAccountQueryDTO);
    }

    /**
     * 根据条件查询员工账户
     * @param userAccountQueryDTO 员工账户参数
     * @return ResultInfo
     */
    @Operation(summary = "根据条件查询员工账户")
    @GetMapping("/getInfoList")
    public ResultInfo<List<UserAccountVO>> getUserAccountList(
            @Validated UserAccountDTO.QueryDTO userAccountQueryDTO) {
        return userAccountService.queryUserAccountList(userAccountQueryDTO);
    }

}
